package com.xq.spring.container;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.Marker;
import org.slf4j.MarkerFactory;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;

/**
 * 容器监听器.实现ApplicationListener<E>接口.
 * 
 * @author 郭凯强
 */
public class ContainerListener implements ApplicationListener<ApplicationEvent> {
	private final Marker marker = MarkerFactory.getMarker("container listener");
	private final Logger logger = LoggerFactory
			.getLogger(ContainerListener.class);

	@Override
	public void onApplicationEvent(ApplicationEvent event) {

		if (event instanceof ContainerEvent) {
			ContainerEvent ctEvent = (ContainerEvent) event;
			logger.debug(marker, "容器事件{}的监听器{}被触发!容器事件对象的额外属性name={}", ctEvent
					.getClass().getName(), ContainerListener.class
					.getSimpleName(), ctEvent.getName());
		} else {
			// org.springframework.context.event.ContextRefreshedEvent
			logger.debug(marker, "容器事件{}的监听器{}被触发!",
					event.getClass().getName(),
					ContainerListener.class.getSimpleName());
		}

	}

}
